package com.china08.yxyapi.api.manage.sch.platform.resource.yxylectureprepack;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lecture.YxyLectureFeedBack;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLectureFeedBackRepository;
import com.china08.yxyapi.util.DateToolUtils;

/**
 * 纠错详情列表
 * 
 * @author liuWeidong
 *
 */
@CrossOrigin
@RestController
public class YxyLectureSchPrePackErrorDetailListSrhController
        extends YxyApiBaseController {

    @Autowired
    private YxyLectureFeedBackRepository yxyLectureFeedBackRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/resource/lectureprepack/error/detail/list.v", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> process(HttpServletRequest request,
            HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String packId = reqModel.packId;
        List<YxyLectureFeedBack> yxyLectureFeedBackLst = yxyLectureFeedBackRepository
                .findByPrepackIdOrderByCreatedDateDesc(packId);

        List<RespModel> respList = new ArrayList<RespModel>();
        for (YxyLectureFeedBack yxyLectureFeedBack : yxyLectureFeedBackLst) {
            RespModel model = new RespModel();
            model.userName = yxyLectureFeedBack.getUserNick();
            model.reason = yxyLectureFeedBack.getReason();
            model.schoolName = yxyLectureFeedBack.getSchoolName();
            model.createdDate = DateToolUtils.format(
                    yxyLectureFeedBack.getCreatedDate(),
                    DateToolUtils.FORMAT_SHORT_YMD);
            model.description = yxyLectureFeedBack.getDescription();
            respList.add(model);
        }
        return respList;
    }

    /** 请求参数 */
    protected static class ReqModel extends YxyApiPageReqModel {

        // 备课包Id
        public String packId;

    }

    /** 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

        // 纠错人名称
        public String userName;
        // 原因
        public String reason;
        // 单位
        public String schoolName;
        // 举报时间
        public String createdDate;
        // 类型
        public String description;

    }
}
